//package com.why.controller;
//
//import com.google.common.collect.Sets;
//import com.why.cachecloud.client.redis.cachecloud.client.lettuce.util.util.RedisUtil;
////import com.why.param.LPushParam;
//import com.why.param.StringSetParam;
//import io.lettuce.core.KeyScanCursor;
//import io.lettuce.core.ScanArgs;
//import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
//import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.annotation.Resource;
//import java.util.Arrays;
//import java.util.Set;
//import java.util.stream.Collectors;
//import java.util.stream.IntStream;
//
///**
// * @Description 提供测试压测
// * @Author why
// * @Version 1.0.0
// * @Since 1.0
// * @Date 2022/9/1
// */
//@RestController
//@Slf4j
//public class TestController {
//    @Resource
//    RedisUtil<String> redisUtil;
//
//    @Resource
//    private StatefulRedisClusterConnection<String, String> clusterConnection;
//
//    @PostMapping("/string/set")
//    public String stringSet(@RequestBody StringSetParam param) {
//        IntStream.range(0, param.getLoopTimes()).forEach(i -> {
//            redisUtil.set(param.getKeyPrefix().concat(System.nanoTime() + ""), param.getValue());
//        });
//        return "SUCCESS";
//    }
//
//    @GetMapping("/string/get")
//    public String stringGet(String keyPrefix) {
//        RedisAdvancedClusterCommands<String, String> commands = clusterConnection.sync();
//        Set<String> allKeys = Sets.newHashSet();
//        KeyScanCursor<String> scanCursor = null;
//        do {
//            if (scanCursor == null) {
//                scanCursor = commands.scan(ScanArgs.Builder.matches(keyPrefix + "*").limit(1000));
//            } else {
//                scanCursor = commands.scan(scanCursor, ScanArgs.Builder.matches(keyPrefix + "*").limit(1000));
//            }
//            allKeys.addAll(scanCursor.getKeys());
//        } while (!scanCursor.isFinished());
//        allKeys.forEach(key -> {
//            String s = redisUtil.get(key);
//            log.info("key-->{},value--->{}", key, s);
//        });
//        return "SUCCESS";
//    }
//
////    @PostMapping("/list/lpush")
////    public String listLPush(@RequestBody LPushParam param) {
////        String[] arr = {"lettuce", "redis", "redisson", "jedis"};
////        IntStream.range(0, param.getLoopTimes()).forEach(i -> {
////            redisUtil.lPush(param.getKey(), trans(arr));
////        });
////        return "SUCCESS";
////    }
//
//    private String[] trans(String[] arr) {
//        Set<String> set = Arrays.asList(arr).stream().map(ele ->
//                ele.concat(String.valueOf(System.nanoTime()))
//        ).collect(Collectors.toSet());
//        return (String[]) set.toArray();
//    }
//
//
//    @PostMapping("/list/lpop")
//    public String listLPop(String key) {
//        redisUtil.lPop(key);
//        return "SUCCESS";
//    }
//}
